package com.java83.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.java83.service.impl.PeopleServiceImpl;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.java83.domain.LzhServiceLog;
import com.java83.service.LzhServiceLogService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务日志Controller
 * 
 * @author ruoyi
 * @date 2022-02-23
 */
@RestController
@RequestMapping("/log")
public class LzhServiceLogController extends BaseController
{
    @Autowired
    private LzhServiceLogService lzhServiceLogService;
    @Autowired
    PeopleServiceImpl peopleService;
    /**
     * 查询服务日志列表
     */
    @RequiresPermissions("lzh_service:log:list")
    @GetMapping("/list")
    public TableDataInfo list(LzhServiceLog lzhServiceLog)
    {
        startPage();
        List<LzhServiceLog> list = lzhServiceLogService.selectLzhServiceLogList(lzhServiceLog);
        return getDataTable(list);
    }


    /**
     * 导出服务日志列表
     */
    @RequiresPermissions("lzh_service:log:export")
    @Log(title = "服务日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LzhServiceLog lzhServiceLog)
    {
        List<LzhServiceLog> list = lzhServiceLogService.selectLzhServiceLogList(lzhServiceLog);
        ExcelUtil<LzhServiceLog> util = new ExcelUtil<LzhServiceLog>(LzhServiceLog.class);
        util.exportExcel(response, list, "服务日志数据");
    }

    /**
     * 获取服务日志详细信息
     */
    @RequiresPermissions("lzh_service:log:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lzhServiceLogService.selectLzhServiceLogById(id));
    }

    @RequiresPermissions("lzh_service:log:query")
    public LzhServiceLog getInfo100(Long id)
    {
        return lzhServiceLogService.selectLzhServiceLogById(id);
    }

    @RequiresPermissions("lzh_service:log:query")
    @GetMapping(value = "/find1/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Long id)
    {
        LzhServiceLog lzhServiceLog = lzhServiceLogService.selectLzhServiceLogById(id);
        lzhServiceLog.setStatus("准备阶段");
        return AjaxResult.success(lzhServiceLog);
    }
    @RequiresPermissions("lzh_service:log:query")
    @GetMapping(value = "/find2/{id}")
    public AjaxResult getInfo2(@PathVariable("id") Long id)
    {
        LzhServiceLog lzhServiceLog = lzhServiceLogService.selectLzhServiceLogById(id);
        lzhServiceLog.setStatus("已完成");
        return AjaxResult.success(lzhServiceLog);
    }

    /**
     * 新增服务日志
     */
    @RequiresPermissions("lzh_service:log:add")
    @Log(title = "服务日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LzhServiceLog lzhServiceLog)
    {
        lzhServiceLog.setStatus("申请阶段");
        lzhServiceLog.setUid(SecurityUtils.getUserId());
        int id = lzhServiceLogService.insertLzhServiceLog(lzhServiceLog);
        lzhServiceLog.setId((long)id);
        peopleService.send(id,lzhServiceLog);
        return toAjax(id);
    }

    /**
     * 修改服务日志
     */
    @RequiresPermissions("lzh_service:log:edit")
    @Log(title = "服务日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LzhServiceLog lzhServiceLog)
    {
        return toAjax(lzhServiceLogService.updateLzhServiceLog(lzhServiceLog));
    }

    /**
     * 删除服务日志
     */
    @RequiresPermissions("lzh_service:log:remove")
    @Log(title = "服务日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lzhServiceLogService.deleteLzhServiceLogByIds(ids));
    }

//    /**
//     * 修改服务日志
//     */
//    @RequiresPermissions("lzh_service:log:edit")
//    @Log(title = "服务日志", businessType = BusinessType.UPDATE)
//    @PutMapping("/edit1")
//    public AjaxResult edit1(@RequestBody LzhServiceLog lzhServiceLog)
//    {
//        peopleService.send(lzhServiceLog);
//        lzhServiceLog.setStatus("申请阶段");
//        return toAjax(lzhServiceLogService.updateLzhServiceLog(lzhServiceLog));
//    }
//    /**
//     * 修改服务日志
//     */
//    @RequiresPermissions("lzh_service:log:edit")
//    @Log(title = "服务日志", businessType = BusinessType.UPDATE)
//    @PutMapping("/edit2")
//    public AjaxResult edit2(@RequestBody LzhServiceLog lzhServiceLog)
//    {
//        lzhServiceLog.setStatus("准备阶段");
//        return toAjax(lzhServiceLogService.updateLzhServiceLog(lzhServiceLog));
//    }

    /**
     * 修改服务日志
     */
    @RequiresPermissions("lzh_service:log:edit")
    @Log(title = "服务日志", businessType = BusinessType.UPDATE)
    @PutMapping("/edit4")
    public AjaxResult edit4(int id)
    {
        return toAjax(lzhServiceLogService.updateLzhServiceLog2(id));
    }

//    /**
//     * 修改服务日志
//     */
//    @RequiresPermissions("lzh_service:log:edit")
//    @Log(title = "服务日志", businessType = BusinessType.UPDATE)
//    @PutMapping("/edit3")
//    public AjaxResult edit3(@RequestBody LzhServiceLog lzhServiceLog)
//    {
//        lzhServiceLog.setStatus("已完成");
//        return toAjax(lzhServiceLogService.updateLzhServiceLog(lzhServiceLog));
//    }

    /**
     * 导出服务日志列表
     */
    @RequiresPermissions("lzh_service:log:export")
    @Log(title = "服务日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export1")
    public void export1(HttpServletResponse response, LzhServiceLog lzhServiceLog)
    {
        lzhServiceLog.setStatus("申请阶段");
        lzhServiceLog.setSid(SecurityUtils.getUserId());
        List<LzhServiceLog> list = lzhServiceLogService.selectLzhServiceLogList(lzhServiceLog);
        ExcelUtil<LzhServiceLog> util = new ExcelUtil<LzhServiceLog>(LzhServiceLog.class);
        util.exportExcel(response, list, "服务日志数据");
    }
}
